class IUP_LINK
-- Creates a label that displays an underlined clickable text. It inherits from 
-- IUP_LABEL. When the cursor is over the text, it is changed to the HAND
--	cursor. By default the text color (fore ground color) is the global 
--	attribute LINKFGCOLOR.
--
-- If the callback is not defined the iup_help function is called with the given
-- URL.
--
-- The IUP_LABEL callbacks BUTTON_CB, ENTERWINDOW_CB and LEAVEWINDOW_CB are 
-- used internally.

inherit
	IUP_LABEL
		redefine
			execute_click
		end

create {ANY}
	link

feature {ANY}

	link (url, title: STRING)
		-- Make a link widget.
		--
		-- url: the destination address of the link. Can be any text. If IupHelp 
		-- is used should be a valid URL. It can be Void. It will set the URL 
		-- attribute.
		-- title: Text to be shown on the link. It can be Void. It will set the 
		-- TITLE attribute.
		local
			a_link: POINTER
		do
			a_link := int_link (url.to_external, title.to_external)
			set_widget(a_link)
		end
	
	-- Attributes

	set_url (state: BOOLEAN)
		-- If set to "False" disables the link. The default value is "True".
		do
			iup_open.set_attribute(Current, "URL", boolean_to_yesno(state))
		end

	-- Callbacks

	set_cb_click (act: FUNCTION[TUPLE[IUP_LINK, STRING], STRING])
		-- Action generated when the link is activated.
		-- ih: identifier of the element that activated the event.
		-- url: the destination address of the link.
		--
		-- Returns: IUP_CLOSE will be processed. If returns IUP_DEFAULT or it is 
		-- not defined, the iup_help function will be called.
		local
			operation: INTEGER
		do
			cb_click := act
			
			if cb_click /= Void then
				operation := 1
			else
				operation := 0
			end
			
			iup_open.set_callback (Current, "ACTION", "Fns", operation)
		end

feature {IUP}

	execute_click (url: STRING): STRING
		do
			Result := cb_click.item([Current, url])
		end

feature {}

	-- For callback
	
	cb_click: FUNCTION[TUPLE[IUP_LINK, STRING], STRING]

	-- Internals

	int_link (url, title: POINTER): POINTER
		external "plug_in"
      alias "{
         location: "${sys}/plugins"
         module_name: "iup"
         feature_name: "IupLink"
         }"
      end
			
end

-- The MIT License (MIT)

-- Copyright (c) 2016, 2017 by German A. Arias

-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in 
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
